package com.gua.common.response;

import com.fasterxml.jackson.annotation.JsonInclude;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

/**
 * 通用返回值
 * 
 * @author huangjj
 *
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
@Getter
@Setter
@Builder
@Schema(description = "响应返回数据对象")
public class AjaxResult<T> {

	@Schema(title = "code", description = "响应码", format = "int32", required = true)
	private int code;

	@Schema(title = "msg", description = "响应信息", example = "成功/失败", required = false)
	private String msg;

	@Schema(title = "data", description = "响应数据")
	private T data;

	public AjaxResult() {

	}

	public AjaxResult(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public AjaxResult(T data) {
		this.code = AjaxResultEnum.SUCCESS.getCode();
		this.msg = AjaxResultEnum.SUCCESS.getMsg();
		this.data = data;
	}

	public AjaxResult(int code, String msg, T data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public AjaxResult(AjaxResultEnum ajaxResultEnum) {
		this.code = ajaxResultEnum.getCode();
		this.msg = ajaxResultEnum.getMsg();
	}

	public AjaxResult<Void> success() {
		return new AjaxResult<Void>(AjaxResultEnum.SUCCESS);
	}

	public AjaxResult<Void> fail() {
		return new AjaxResult<Void>(AjaxResultEnum.FAIL);
	}

}
